针对如何处理Maven项目中的依赖关系?和maven项目之间依赖这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展3.将maven项目jar纳入maven仓库,Mave项目依赖另外一个Mave
针对如何处理Maven项目中的依赖关系?和maven项目之间依赖这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展3.将maven项目jar纳入maven仓库,Mave项目依赖另外一个Maven项目、c – CMake – 自动解析预编译头的依赖关系?、c# – 如何处理MVC中的2对1关系?、ERESOLVE 无法解析我的 React Native Web 项目中的依赖关系树等相关知识,希望可以帮助到你。
本文目录一览:- 如何处理Maven项目中的依赖关系?(maven项目之间依赖)
- 3.将maven项目jar纳入maven仓库,Mave项目依赖另外一个Maven项目
- c – CMake – 自动解析预编译头的依赖关系?
- c# – 如何处理MVC中的2对1关系?
- ERESOLVE 无法解析我的 React Native Web 项目中的依赖关系树
如何处理Maven项目中的依赖关系?(maven项目之间依赖)
如果要使用X
类,则需要将X
声明为依赖项,而不是父项。
3.将maven项目jar纳入maven仓库,Mave项目依赖另外一个Maven项目
1若想让maven项目依赖另外一个maven项目,被依赖的项目要在maven仓库中有相应的jar包,所以要对依赖的项目执行mvninstall命令。 2新建第二个项目模块HelloFriend目录及约定的目录结构 vcmRlcj0="1" cellspacing="0" cellpadding="0"> HelloFriend --src ----
1 若想让maven项目依赖另外一个maven项目,被依赖的项目要在maven仓库中有相应的jar包,所以要对依赖的项目执行mvninstall命令。
2 新建第二个项目模块HelloFriend目录及约定的目录结构
vcmRlcj0="1" cellspacing="0" cellpadding="0">
HelloFriend --src -----main ----------java ----------resources -----test ---------java ---------resources --pom.xml |
3 在项目HelloFriend根目录建立pom.xml
|
4 在src/main/java/cn/toto/maven目录下新建文件HelloFriend.java文件
package cn.toto.maven;
import cn.toto.maven.Hello;
public class HelloFriend {
public String sayHelloToFriend(String name){
Hello hello = new Hello(); String str = hello.sayHello(name)+" I am "+this.getMyName(); System.out.println(str); return str; }
public String getMyName(){ return "John"; }
} |
5 在/src/test/java/cn/toto/maven目录下新建测试文件HelloFriendTest.java
package cn.toto.maven;
import static junit.framework.Assert.assertEquals;
import org.junit.Test;
import cn.toto.maven.Hello;
public class HelloFriendTest { @Test public void tesHelloFriend(){
HelloFriend helloFriend = new HelloFriend(); String results = helloFriend.sayHelloToFriend("tuzuoquan"); assertEquals("Hello tuzuoquan! I am John",results);
} } |
6 在HelloFriend目录下执行命令mvn命令(注意到HelloFriend文件夹)
7 重新在HelloFriend目录下执行命令mvnpackage
c – CMake – 自动解析预编译头的依赖关系?
我当前的问题是,CMake不会解析您为自定义命令指定的依赖关系的依赖关系.例如,假设以下结构:
pch.h |- dependA.h |- dependB.h ...
只提供pch.h作为依赖关系将导致在相应的makefile中生成适当的目标,跟踪对pch.h的更改.但是,CMake不解析pch.h中的include,因此不会识别dependA.h和dependB.h的更改.如果依赖关系依赖于依赖性等等,这将会延续下去.
注意:我知道,PCH依赖关系可以和经常改变的事实使整个过程成为问题.然而,这只是它的方式,我不能真正做任何事情.
由于任务不是太难,有几个明显的想法可以想到:
解决方案A:
手动输入所有依赖项.显然这是有效的,但是如果没有任何规模,那么它就是无聊的.
解决方案B:
如果可能,请编写一个自动化进程并解析包含“手动”的CMake功能.
解决方案C:
使用不同的语言(例如Python)执行类似的操作,并且只需要为CMake提供添加到自定义命令的依赖关系列表.
解决方案D:
使用gcc / g的功能来解析和打印PCH的依赖关系树,并解析输出以提取依赖关系列表.
我的问题是:有没有人知道一个更方便快捷的方式来完成这个工作?
解决方法
add_custom_command( OUTPUT outFile COMMAND ... IMPLICIT_DEPENDS CXX "pch.h")
IMPLICIT_DEPENDS选项使生成的构建系统在构建时扫描给定输入文件的隐式依赖关系.但是,它只支持Makefile生成器.
c# – 如何处理MVC中的2对1关系?
public class Game { public Player Player1 { get; set; } [required] public int Player1Id { get; set; } public Player Player2 { get; set; } [required] public int Player2Id { get; set; } }
尝试将此模型迁移到数据库时,出现以下错误:
Introducing FOREIGN KEY constraint ‘FK_dbo.Games_dbo.Players_Player2Id’ on table ‘Games’ may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION,or modify other FOREIGN KEY constraints.
(this stackoverflow question的答案很好地解释了为什么我会收到此错误.)
为了避免这个错误,我添加了以下流畅的API代码:
modelBuilder.Entity<Game>() .Hasrequired(c => c.Player1) .WithMany() .HasForeignKey(c => c.Player1Id) .WillCascadeOnDelete(false); modelBuilder.Entity<Game>() .Hasrequired(c => c.Player2) .WithMany() .HasForeignKey(c => c.Player2Id) .WillCascadeOnDelete(false);
我现在遇到的问题是,当我尝试删除一个Player,其Id在一个或多个游戏中被引用.
The operation Failed: The relationship Could not be changed because one or more of the foreign-key properties is non-nullable. When a change is made to a relationship,the related foreign-key property is set to a null value. If the foreign-key does not support null values,a new relationship must be defined,the foreign-key property must be assigned another non-null value,or the unrelated object must be deleted.
如果我正确地理解了这个错误,我得到这个错误,因为游戏失败的一个外键约束(级联删除是假的,所以游戏不会随玩家一起被删除.相反,Player1Id(或Player2Id)是设置为null,这会打破约束,因为它们都是必需的且不可为空的)
所以我尝试在Seed()方法中创建一个类似this SO question的触发器.
context.Database.ExecutesqlCommand("CREATE TRIGGER Game_Player_Del on dbo.Players instead of delete as " + "set nocount on " + "delete from dbo.Games where Player1Id in (select Id from deleted) or " + "Player2Id in (Select Id from deleted) " + "delete from dbo.Players where Id in (select Id from deleted)");
当我检查我的数据库时,触发器确实被添加,但它似乎不起作用,因为我仍然得到与添加触发器之前相同的错误.
那么,我该怎么做才能使这项工作按预期进行? (删除播放器也删除关联的游戏,删除游戏不会删除播放器)
编辑:我想到的一个可能的解决方案是编辑我的控制器中的删除方法,首先获得Player1Id或Player2Id等于Player.Id的所有游戏,删除那些然后删除播放器,但(我认为)删除播放器时我不必担心游戏,实体框架应该为我做这个.
编辑2 :(回应usr的评论)这是我的删除代码:
控制器:
[HttpPost,ActionName("Delete")] [ValidateAntiForgeryToken] public ActionResult DeleteConfirmed(int id) { repo.deletePlayer(id); return RedirectToAction("Index"); }
回购:
public void deletePlayer(int id) { using (var context = new TennisContext()) { player = context.Players.Find(id); context.Entry(player).State = EntityState.Deleted; context.SaveChanges(); } }
编辑3:在删除播放器之前,我设法通过查询和删除受影响的游戏来使其工作.
回购代码:
public void deletePlayer(int id) { using (var context = new TennisContext()) { player = context.Players.Find(id); List<Game> playerGames = context.Games.Where(g => g.Player1Id == id || g.Player2Id == id).ToList(); foreach (Game g in playerGames) { context.Entry(g).State = EntityState.Deleted; } context.Entry(player).State = EntityState.Deleted; context.SaveChanges(); } }
解决方法
由于您无法使用自动级联,请手动执行此操作.
ERESOLVE 无法解析我的 React Native Web 项目中的依赖关系树
如何解决ERESOLVE 无法解析我的 React Native Web 项目中的依赖关系树?
我得到了一个我正在尝试制作的 React Native Web 模板。所以我为我的状态管理安装了 class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
LearnComposeTheme {
// A surface container using the ''background'' color from the theme
Surface(color = MaterialTheme.colors.primaryVariant) {
Greeting("Android")
}
}
}
}
}
@Composable
fun Greeting(name: String) {
Row() {
Column(modifier = Modifier.padding(16.dp)) {
Text(
text = "Hello $name!",modifier = Modifier.padding(bottom = 8.dp).fillMaxWidth(),style = MaterialTheme.typography.h5
)
LazyColumnDemo()
}
}
}
@Composable
fun LazyColumnDemo() {
val list = listof(
"A","B","C","D"
) + ((0..100).map { it.toString() })
LazyColumn(modifier = Modifier.fillMaxHeight()) {
items(items = list,itemContent = { item ->
when (item) {
"A" -> {
Text(text = item,style = TextStyle(fontSize = 80.sp))
}
"B" -> {
Button(onClick = {
}) {
Text(text = item,style = TextStyle(fontSize = 80.sp))
}
}
"C" -> {
//Do nothing
}
"D" -> {
Text(text = item)
}
else -> {
Text(text = item,style = TextStyle(fontSize = 80.sp))
}
}
})
}
}
@Preview(showBackground = true)
@Composable
fun DefaultPreview() {
LearnComposeTheme {
Greeting("Android")
}
}
。但是我在安装后运行项目时遇到了一个错误。
@reduxjs/toolkit
这些是每个目录的 package.json 文件的依赖项和 devDependencies。 根目录/包/通用
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! Found: react@16.9.0
npm ERR! node_modules/react
npm ERR! peer react@"16.9.0" from react-native@0.61.5
npm ERR! node_modules/react-native
npm ERR! peer react-native@"^0.61.0" from @react-native-community/cli@3.2.1
npm ERR! node_modules/@react-native-community/cli
npm ERR! @react-native-community/cli@"^3.0.0" from react-native@0.61.5
npm ERR! react-native@"^0.61.5" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! @reduxjs/toolkit@"^1.6.0" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: react@17.0.2
npm ERR! node_modules/react
npm ERR! peerOptional react@"^16.14.0 || ^17.0.0" from @reduxjs/toolkit@1.6.0
npm ERR! node_modules/@reduxjs/toolkit
npm ERR! @reduxjs/toolkit@"^1.6.0" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict,or retry
npm ERR! this command with --force,or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
root/packages/mobile
{
"name": "@monorepo/common","version": "1.0.0","main": "dist/index.js","scripts": {
"build": "rm -rf dist && tsc","watch": "tsc --watch"
},"license": "MIT","dependencies": {
"@reduxjs/toolkit": "^1.6.0","grunt-sync": "^0.8.2","react-native": "^0.61.5"
},"devDependencies": {
"@types/react-native": "^0.61.16","grunt": "^1.4.1","grunt-contrib-watch": "^1.1.0","typescript": "^3.8.2"
}
}
root/packages/web
"dependencies": {
"react": "16.8.6","react-native": "0.60.5"
},"devDependencies": {
"@monorepo/common": "1.0.0","@babel/core": "^7.5.0","@babel/runtime": "^7.5.0","@react-native-community/eslint-config": "^0.0.3","@types/jest": "^24.0.18","@types/react": "^16.9.2","@types/react-native": "^0.60.14","@types/react-test-renderer": "^16.9.0","babel-jest": "^24.1.0","jest": "^24.1.0","metro-react-native-babel-preset": "0.54.1","react-test-renderer": "16.8.6","typescript": "^3.6.3"
}
我尝试升级到最新的软件包,但还是遇到了同样的错误,这次冲突在别的地方,而且最上面的依赖项仍然是"dependencies": {
"@monorepo/common": "1.0.0","@testing-library/jest-dom": "^4.2.4","@testing-library/react": "^9.3.2","@testing-library/user-event": "^7.1.2","@types/jest": "^24.0.0","@types/node": "^12.0.0","@types/react": "^16.9.0","@types/react-dom": "^16.9.0","react": "^16.12.0","react-dom": "^16.12.0","react-native-web": "^0.12.1","react-scripts": "3.4.0","typescript": "~3.7.2"
},"cross-env": "^7.0.3","uuid": "^8.3.2"
}
。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
我们今天的关于如何处理Maven项目中的依赖关系?和maven项目之间依赖的分享就到这里,谢谢您的阅读,如果想了解更多关于3.将maven项目jar纳入maven仓库,Mave项目依赖另外一个Maven项目、c – CMake – 自动解析预编译头的依赖关系?、c# – 如何处理MVC中的2对1关系?、ERESOLVE 无法解析我的 React Native Web 项目中的依赖关系树的相关信息,可以在本站进行搜索。
本文标签: